32b899
@@ -34,6 +34,7 @@
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
 import org.apache.calcite.rex.RexUtil;
 import org.apache.calcite.rex.RexVisitorImpl;
 import org.apache.calcite.sql.type.SqlTypeName;
@@ -103,13 +104,15 @@
public void onMatch(RelOptRuleCall call) {
 
     if (!newLeftPredicate.isAlwaysTrue()) {
       RelNode curr = lChild;
-      lChild = filterFactory.createFilter(lChild, newLeftPredicate);
+      lChild = filterFactory.createFilter(
+          lChild, newLeftPredicate.accept(new RexReplacer(lChild)));
       call.getPlanner().onCopy(curr, lChild);
     }
 
     if (!newRightPredicate.isAlwaysTrue()) {
       RelNode curr = rChild;
-      rChild = filterFactory.createFilter(rChild, newRightPredicate);
+      rChild = filterFactory.createFilter(
+          rChild, newRightPredicate.accept(new RexReplacer(rChild)));
       call.getPlanner().onCopy(curr, rChild);
     }
 
@@ -161,7 +164,7 @@
private RexNode getTypeSafePred(RelOptCluster cluster, RexNode rex, RelDataType
     return typeSafeRex;
   }
 
-  private static class InputRefValidator  extends RexVisitorImpl<Void> {
+  private static class InputRefValidator extends RexVisitorImpl<Void> {
 
     private final List<RelDataTypeField> types;
     protected InputRefValidator(List<RelDataTypeField> types) {
@@ -201,5 +204,17 @@
private boolean areTypesCompatible(RelDataType type1, RelDataType type2) {
       return false;
     }
   }
-}
 
+  /* Changes the type of the input references to adjust nullability */
+  private static class RexReplacer extends RexShuttle {
+    private final RelNode input;
+
+    RexReplacer(RelNode input) {
+      this.input = input;
+    }
+
+    @Override public RexNode visitInputRef(RexInputRef inputRef) {
+      return RexInputRef.of(inputRef.getIndex(), input.getRowType());
+    }
+  }
+}
